from app.routes.auth import auth_bp
from app.routes.inventory import inventory_bp
from app.routes.supplier import supplier_bp
from app.routes.stock_docs import stock_docs_bp
from app.routes.transfer import transfer_bp
from app.routes.zero_stock import zero_stock_bp
from app.routes.help import help_bp
from app.routes.user import user_bp
from flask_wtf.csrf import generate_csrf

def register_routes(app):
    # 注册蓝图（按模块分组）
    app.register_blueprint(auth_bp)
    app.register_blueprint(inventory_bp)
    app.register_blueprint(supplier_bp)
    app.register_blueprint(stock_docs_bp)
    app.register_blueprint(transfer_bp)
    app.register_blueprint(zero_stock_bp)
    app.register_blueprint(help_bp)
    app.register_blueprint(user_bp)
    
    # 提供CSRF令牌的API端点（用于AJAX请求）
    @app.route('/api/csrf-token', methods=['GET'])
    def get_csrf_token():
        return {'csrf_token': generate_csrf()}
    
    # 全局上下文处理器，使CSRF令牌在所有模板中可用
    @app.context_processor
    def inject_csrf_token():
        return {'csrf_token': generate_csrf()}